#!/bin/bash

#Интервал проверок, секунд
CHECK_INTERVAL=60

PING_HOST='ya.ru'
#PING_GW='10.121.0.17'
#PING_GW='172.17.108.1'
PING_GW='109.236.102.129'

LOGFILE='/root/telixLogger.LOG'


{
#ping -c1 -a $PING_HOST &>/dev/null
PING_status=0
goodCount=0
globalGoodCount=0
hangupCount=0
echo -n "Запуск мониторинга соединения: " && date
	while [ true ];
	do
	ping -c2 -W50 -a $PING_HOST &>/dev/null
	PING_status=$?
		if [ ! $PING_status -eq 0 ]; then
		(( hangupCount++ ))
		echo
		echo "Telix not worked! This is $hangupCount time. Restarting. "`date`
		#Now Ping Local GW
		ping -c2 -a $PING_GW
		echo "Ping Local GW result: $?;"
		goodCount=0
		date
		else
			if [ $globalGoodCount -gt $goodCount ]; then
			echo -n ".$goodCount($globalGoodCount)"
			else
			echo -n ".$goodCount"
			fi
		(( goodCount++ ))
		(( globalGoodCount++ ))
		fi
	sleep $CHECK_INTERVAL
	done

exit 0

} | tee -a $LOGFILE